var macro2;
var macro;
var jsLF = "\n";
var i, retcode, errtext;
var MyDelay = 0;
var MyPosts;

var Aldeias;

var espioes;
var cavalariaLeve;
var command;
var num = 0;
i = 0;

espioes = 1;
cavalariaLeve = 7;

//var atacado;
//var atacante;

var unit_input_spear = 0;
var unit_input_spy = 0;
var unit_input_ram = 0;
var unit_input_knight = 0;
var unit_input_sword = 0;
var unit_input_light = 0;
var unit_input_catapult = 0;
var unit_input_snob = 0;
var unit_input_axe = 0;
var unit_input_marcher = 0;
var unit_input_archer = 0;
var unit_input_heavy = 0;




//
//for(var j = 0; j<=3;J++){
//    atacante = "167656";
//    atacado = "";
//    unit_input_axe = 0;
//    unit_input_spy = 50;
//    unit_input_ram = 1;
//    unit_input_catapult = 0;
//    atacar();
//    zera();
//}



//
//atacante = "154188";
//atacado = "156772";
//unit_input_axe = 0;
//unit_input_spy = 200;
//unit_input_ram = 0;
//unit_input_catapult = 0;
//atacar();
//zera();




//
////full
//atacante = "151866";
//atacado = "151099";
//unit_input_axe = 7000;
//unit_input_spy = 200;
//unit_input_ram = 100;
//unit_input_catapult = 250;
//atacar();
//zera();


var Atacante;
var Atacado;

Atacante = new Array();
Atacado = new Array();


//
//Aldeias.push("49501");
//Aldeias.push("49845");
//Aldeias.push("48224");
//Aldeias.push("47158");
//Aldeias.push("54529");
//Aldeias.push("60368");
//Aldeias.push("51167");




ataque("49501", "47439");
ataque("49845", "44987");
ataque("48224", "47467");
ataque("47158", "46629");
ataque("54529", "42626");
ataque("60368", "48571");
ataque("51167", "46544");






fake();
var j = 0;
var text;

function ataque(atacan, atacad){
    for(j = 0; j<=4;j++){
        Atacado.push(atacad);
        Atacante.push(atacan);
    }        
}

macro = "";

while(true){

    //    alert(num);

    macro = "CODE:";
    macro += "TAB T=2" + jsLF;
       
    iimPlay(macro);


    macro = "CODE:";
    macro += "ADD !EXTRACT {{!URLCURRENT}}";
    iimPlay(macro);


    text = iimGetLastExtract();
    command = text.substr(text.indexOf("action=command&amp;h=")+21,4);

    macro = "CODE:";
    
    macro += "TAG POS=1 TYPE=INPUT:SUBMIT FORM=ACTION:http://br37.tribalwars.com.br/game.php?village="+atacante+"&screen=place&action=command&h="+ command +" ATTR=ID:troop_confirm_go" + jsLF;
//    macro += "WAIT SECONDS=" + MyDelay + jsLF;
    iimPlay(macro);
//    if (retcode < 0) {              // an error has occured
//        errtext = iimGetLastError();
//        alert(errtext);
//        macro2 = "CODE:";
//        macro2 += "WAIT SECONDS=10" + jsLF;
//        iimPlay(macro2);
//    }

    num++;
    
}





function zera(){
    unit_input_spear = 0;
    unit_input_spy = 0;
    unit_input_ram = 0;
    unit_input_knight = 0;
    unit_input_sword = 0;
    unit_input_light = 0;
    unit_input_catapult = 0;
    unit_input_snob = 0;
    unit_input_axe = 0;
    unit_input_marcher = 0;
    unit_input_archer = 0;
    unit_input_heavy = 0;
}



function fake(){
    unit_input_spear = 0;
    unit_input_spy = 0;
    unit_input_ram = 0;
    unit_input_knight = 0;
    unit_input_sword = 0;
    unit_input_light = 0;
    unit_input_catapult = 1;
    unit_input_snob = 0;
    unit_input_axe = 0;
    unit_input_marcher = 0;
    unit_input_archer = 0;
    unit_input_heavy = 0;
}


function atacar(){

    macro = "CODE:";
    macro += "URL GOTO=http://br37.tribalwars.com.br/game.php?village="+atacante+"&screen=place&target="+ atacado + jsLF;

    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_spear CONTENT="+unit_input_spear + jsLF;
    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_spy CONTENT="+unit_input_spy + jsLF;
    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_ram CONTENT="+unit_input_ram + jsLF;
    //    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_knight CONTENT="+unit_input_knight + jsLF;
    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_sword CONTENT="+unit_input_sword + jsLF;
    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_light CONTENT="+unit_input_light + jsLF;
    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_catapult CONTENT="+unit_input_catapult + jsLF;
    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_snob CONTENT="+unit_input_snob + jsLF;
    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_axe CONTENT="+unit_input_axe + jsLF;
    //    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_marcher CONTENT="+unit_input_marcher + jsLF;
    //    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_archer CONTENT="+unit_input_archer + jsLF;
    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_heavy CONTENT="+unit_input_heavy + jsLF;
    //    macro += "TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:units_form ATTR=ID:target_attack" + jsLF;
    //    macro += "TAG POS=1 TYPE=TD ATTR=ID:inner-border EXTRACT=HTM";

    retcode = iimPlay(macro);
    if (retcode < 0) {              // an error has occured
        errtext = iimGetLastError();
        alert(errtext);
        macro2 = "CODE:";
        macro2 += "WAIT SECONDS=5" + jsLF;
        iimPlay(macro2);
    }

    text = iimGetLastExtract();
    command = text.substr(text.indexOf("action=command&amp;h=")+21,4);

    macro = "CODE:";
    
    if(unit_input_catapult>0)
        macro += "TAG POS=1 TYPE=SELECT FORM=ACTION:/game.php?village="+atacante+"&screen=place&action=command&h="+ command +" ATTR=NAME:building CONTENT=%farm"+ jsLF;
    macro += "TAG POS=1 TYPE=INPUT:SUBMIT FORM=ACTION:http://br35.tribalwars.com.br/game.php?village="+atacante+"&screen=place&action=command&h="+ command +" ATTR=ID:troop_confirm_go" + jsLF;
    macro += "WAIT SECONDS=" + MyDelay + jsLF;
    retcode = iimPlay(macro);
    if (retcode < 0) {              // an error has occured
        errtext = iimGetLastError();
        alert(errtext);
        macro2 = "CODE:";
        macro2 += "WAIT SECONDS=10" + jsLF;
        iimPlay(macro2);
    }


}


function logui(txtLog){
    log = txtLog + jsLF+ log;
    iimDisplay(log);
}
